package com.itboye.mengwu.testpic.ui;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.core.utils.XImageLoader;
import com.itboye.mengwu.R;

public class ImageBucketAdapter extends BaseAdapter {

	Context act;
	/**
	 * 图片集列表
	 */
	ArrayList<String> dataList;

	public ImageBucketAdapter(Activity act, ArrayList<String> list) {
		this.act = act;
		dataList = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		int count = 0;
		if (dataList != null) {
			count = dataList.size();
		}
		return count+1;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	class Holder {
		private ImageView iv;
		private ImageView selected;
		private TextView name;
		private TextView count;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		Holder holder;
		if (arg1 == null) {
			holder = new Holder();
			arg1 = View.inflate(act, R.layout.item_image_bucket, null);
			holder.iv = (ImageView) arg1.findViewById(R.id.image);
			holder.selected = (ImageView) arg1.findViewById(R.id.isselected);
			holder.name = (TextView) arg1.findViewById(R.id.name);
			holder.count = (TextView) arg1.findViewById(R.id.count);
			arg1.setTag(holder);
		} else {
			holder = (Holder) arg1.getTag();
		}
//		holder.count.setText("" + dataList.size());
//		holder.name.setText(item.bucketName);
//		holder.selected.setVisibility(View.GONE);
		if(arg0==dataList.size()){
			holder.iv.setImageResource(R.drawable.icon_addpic_unfocused);
		}
		else {
			holder.iv.setTag("file://"+dataList.get(arg0));
			XImageLoader.load("file://"+dataList.get(arg0),holder.iv);
		} 
		return arg1;
	}

}
